<?php 
	namespace Admin\Controller;


	class LinkController extends AdminController
	{
		//数据库操作类
		private $_model = null;

		//初始化操作
		public function _initialize()
		{
			parent::_initialize();
			$this->_model = D('Link');
		}
		public function index()
		{
			$list = $this->_model->order('id desc')->select();
			$this->assign('list',$list);
			$this->display();
		}
		//添加页面
		public function add()
		{
			$this->display();
		}
		//添加链接操作
		public function doadd()
		{
			if(!$this->_model->create()){
				$this->error($this->_model->getError());
				exit;
			}

			if($this->_model->add() > 0){
				$this->success("添加成功！",U('Link/index'));
			}else{
				$this->error("添加失败！");
			}
		}

		public function del()
		{
			if($this->_model->delete($_GET['id']) > 0){
				$this->success("删除成功！",U('Link/index'));
			}else{
				$this->error("删除失败");
			}
		}

		public function edit()
		{
			$vo = $this->_model->where(array('id'=>array('eq',I('id'))))->find();
			$this->assign('vo',$vo);
			$this->display();
		}

		public function save()
		{
			if(!$this->_model->create()){
				$this->error($this->_model->getError());
				exit;
			}
			//执行修改 
			if($this->_model->save() >= 0){
				$this->success("修改成功！",U('Link/index'));
			}else{
				$this->error("修改失败");
			}
		
		}

	}